package AtmSystem;

import java.util.*;
import java.io.*;

public class DaliyDBIO {



    public DaliyDB loadDaliyDB (String filename) throws IOException,
        FileNotFoundException {

        DaliyDB myDaliyDB = new DaliyDB();

        BufferedReader reader =
            new BufferedReader(new FileReader(filename));
        String line =  reader.readLine();

        while (line != null) {

            Daliy myDaliy = null;
            myDaliy = readDaliy(line);
            myDaliyDB.add(myDaliy);

            line =  reader.readLine();
        }

		reader.close();

        return myDaliyDB;
    }


    private Daliy readDaliy (String line) {

        StringTokenizer tokenizer = new StringTokenizer(line, "/");
		
		String IP = tokenizer.nextToken();
		String name = tokenizer.nextToken();
		String action = tokenizer.nextToken();

        Daliy myDaliy =new Daliy (IP,name,action);

      return myDaliy;
      }

	  public boolean writerDaliy (String filename ,String newIP,String newName,String newAction) throws IOException,
        FileNotFoundException {
	 try
     {
		PrintWriter writer=
            new PrintWriter (new FileWriter(filename,true));

        String daliyInfo = "";
		daliyInfo+= newIP;
		daliyInfo+= "/";
		daliyInfo+= newName;
		daliyInfo+= "/";
		daliyInfo+= newAction;
		daliyInfo+= "/";
		writer.println(daliyInfo);
	
			 

			writer.close();
        return true;
		}
     catch (FileNotFoundException e)
		{
		 return false;
		}   
	}


}
